from queue import Queue
from threading import Thread
from PyQt5.QtCore import QObject, pyqtSignal

class DownloadManager(QObject):
    progress_updated = pyqtSignal(int)
    
    def __init__(self):
        super().__init__()
        self.queue = Queue()
        self.workers = []
        
    def add_task(self, url):
        self.queue.put(url)
        if not self.workers:
            self._start_worker()
            
    def _start_worker(self):
        worker = Thread(target=self._process_queue)
        worker.daemon = True
        worker.start()
        self.workers.append(worker)
        
    def _process_queue(self):
        while True:
            url = self.queue.get()
            # 执行下载逻辑
            self.progress_updated.emit(100)
            self.queue.task_done()